package com.ecjtu.stadiumre_servations.controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ecjtu.stadiumre_servations.entity.domain.Booking;
import com.ecjtu.stadiumre_servations.entity.dto.BookingDTO;
import com.ecjtu.stadiumre_servations.response.Result;
import com.ecjtu.stadiumre_servations.service.BookingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/booking")
public class BookingController {
    @Autowired
    private BookingService bookingService;
    /**
     * 创建预约
     */
    @PutMapping("/createBooking")
    public Result createBooking(@RequestBody BookingDTO bookingDTO){
        return bookingService.createBookings(bookingDTO);
    }
    /**
     * 查询预约
     */
    @GetMapping("/bookings")
    public Result bookings(Page<Booking> page){
        return bookingService.bookings(page);
    }
    /**
     * 根据ID查询预约
     */
    @GetMapping("/selectBookingsById/{id}")
    public Result selectBookingsById( Page<Booking> page, @PathVariable  String id){
        return bookingService.selectBookingsById(page,id);
    }

    @GetMapping("/selectBookingsByUserId/{userId}")
    public Result selectBookingsByUserId( Page<Booking> page, @PathVariable String userId){
        return bookingService.selectBookingsByUserId(page,userId);
    }

    @GetMapping("/selectBookingByBookingId")
    public Result selectBookingByBookingId(Page<Booking> page, @RequestParam String bookingId){
        return bookingService.selectBookingByBookingId(page,bookingId);
    }
    /**
     * 取消预约
     */
    @PostMapping("/cancelBooking/{bookingId}")
    public Result cancelBooking(@PathVariable String bookingId){
        return bookingService.cancelBooking(bookingId);
    }
    /**
     * 包场
     */
    @PutMapping("/bookingTheEntireVenue")
    public Result bookingTheEntireVenue(@RequestBody BookingDTO bookingDTO,String venueName){
        return bookingService.bookingTheEntireVenue(bookingDTO,venueName);
    }
    @GetMapping("/getAvailableTimeSlots")
    public List<LocalDateTime[]> getAvailableTimeSlots(@RequestParam String venueId){
        return bookingService.getAvailableTimeSlots(venueId);
    }
}
